// src/api/academicAchievement.js
import request from '@/utils/request'

// 创建学术成果
export function createAcademicAchievement(data) {
	return request({
		url: '/api/academic-achievements',
		method: 'post',
		data
	})
}

// 创建学术成果（JSON格式，无文件）
export function createAcademicAchievementJson(data) {
	return request({
		url: '/api/academic-achievements/json',
		method: 'post',
		data
	})
}

// 获取个人学术成果列表
export function getMyAcademicAchievements(params) {
	return request({
		url: '/api/academic-achievements/my',
		method: 'get',
		params
	})
}

// 获取学术成果详情
export function getAcademicAchievement(id) {
	return request({
		url: `/api/academic-achievements/${id}`,
		method: 'get'
	})
}

// 更新学术成果
export function updateAcademicAchievement(id, data) {
	return request({
		url: `/api/academic-achievements/${id}`,
		method: 'put',
		data
	})
}

// 更新学术成果（JSON格式，无文件）
export function updateAcademicAchievementJson(id, data) {
	return request({
		url: `/api/academic-achievements/${id}/json`,
		method: 'put',
		data
	})
}

// 删除学术成果
export function deleteAcademicAchievement(id) {
	return request({
		url: `/api/academic-achievements/${id}`,
		method: 'delete'
	})
}

// 上传学术成果附件
export function uploadAcademicAchievementAttachment(achievementId, file, fileType = '证明材料') {
	const formData = new FormData()
	formData.append('file', file)
	formData.append('fileType', fileType)
	return request({
		url: `/api/academic-achievements/${achievementId}/attachments`,
		method: 'post',
		data: formData,
		headers: { 'Content-Type': 'multipart/form-data' }
	})
}

// 获取学术成果附件
export function getAcademicAchievementAttachments(achievementId) {
	return request({
		url: `/api/academic-achievements/${achievementId}/attachments`,
		method: 'get'
	})
}

// 删除附件
export function deleteAcademicAchievementAttachment(attachmentId) {
	return request({
		url: `/api/academic-achievements/attachments/${attachmentId}`,
		method: 'delete'
	})
}

// 获取待审核学术成果列表（管理员）
export function getPendingAcademicAchievements() {
	return request({
		url: '/api/academic-achievements/pending',
		method: 'get'
	})
}

// 获取所有学术成果列表（管理员）
export function getAllAcademicAchievements() {
	return request({
		url: '/api/academic-achievements/all',
		method: 'get'
	})
}

// 获取教师列表（用于筛选）
export function getTeachersList() {
	return request({
		url: '/api/academic-achievements/teachers',
		method: 'get'
	})
}

// 根据作者姓名搜索成果ID列表
export function searchByAuthorName(authorName) {
	return request({
		url: '/api/academic-achievements/search-by-author',
		method: 'get',
		params: { authorName }
	})
}

// 审核学术成果（管理员）
export function reviewAcademicAchievement(achievementId, data) {
	return request({
		url: `/api/academic-achievements/${achievementId}/review`,
		method: 'post',
		data
	})
}
